<?php function threadedComments($comments, $options) {
    $commentClass = '';
    if ($comments->authorId) {
        if ($comments->authorId == $comments->ownerId) {
            $commentClass .= ' comment-by-author';  //如果是文章作者的评论添加 .comment-by-author 样式
        } else {
            $commentClass .= ' comment-by-user';  //如果是评论作者的添加 .comment-by-user 样式
        }
    } 
    $commentLevelClass = $comments->_levels > 0 ? ' comment-child' : ' comment-parent';  //评论层数大于0为子级，否则是父级
?>
<div id="<?php $comments->theId(); ?>">
    <div class="card" style="margin-bottom: 0.5rem;">
      <div class="row align-items-center justify-content-between">
            <div class="col rounded-circle text-center align-self-center">
            <?php $comments->gravatar('40', ''); ?>
            </div>
            <div class="col text-center align-self-center">
                <span class="border border-light">
              <a href="<?php $comments->permalink(); ?>"><?php $comments->author(); ?></a><!-- 作者 -->
              </span>
            </div>
            <div class="col text-center align-self-center">
                <span class="border border-light">
              <?php $comments->date('Y-m-d H:i'); ?>
                </span><!-- 评论时间 -->
            </div>
            <div class="col text-center align-self-center">
              <button type="button" class="btn btn-outline-light">
                <?php $comments->reply(回复); ?></button><!-- 回复按钮 -->
            </div>
        </div>
        <hr>
        <div class="row mx-auto">
            <div class="col-12 justify-content-center">
            <?php $comments->content(); ?><!-- 评论内容 -->
            </div>
        </div>
        <?php if ($comments->children) { ?> 
        <div class="container comment-children">
            <?php $comments->threadedComments($options); ?><!-- 嵌套内容 -->
        </div>
        <?php } ?> 
    </div>
</div>
<?php } ?>
<div class="container" style="margin-top: 2rem;">
    <?php $this->comments()->to($comments); ?>
    <?php if ($comments->have()) : ?>
    <div class="alert alert-secondary" role="alert">
        <?php $this->commentsNum(_t('暂无评论'), _t('一条评论'), _t('已有 %d 条评论')); ?>
    </div>
    <?php $comments->listComments(); ?>
    <?php $comments->pageNav('&laquo; 前一页', '后一页 &raquo;'); ?>
    <?php endif; ?>

    <?php if($this->allow('comment')): ?>
        
            <div class="cancel-comment-reply">
            <?php $comments->cancelReply(); ?>
            </div>
        
            <div class="alert alert-danger" role="alert"><h5><?php _e('添加新评论'); ?></h5></div>
        <div id="<?php $this->respondId(); ?>" class="respond">
        <form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form">
        <?php if($this->user->hasLogin()): ?>
                    <h5><?php _e('当前身份'); ?> <span class="badge badge-secondary"><a href="<?php $this->options->profileUrl(); ?>"><?php $this->user->screenName(); ?></a></span></h5>
                    <a href="<?php $this->options->logoutUrl(); ?>" title="Logout"><?php _e('退出'); ?> &raquo;</a>
        <?php else: ?>
          <div class="row">
            <div class="col">
              <input type="text" class="form-control text" placeholder="<?php _e('昵称'); ?>（必填）" name="author" id="author" value="<?php $this->remember('author'); ?>">
            </div>
            <div class="col">
              <input type="email" class="form-control text" placeholder="邮箱（必填）"name="mail" id="mail" value="<?php $this->remember('mail'); ?>"<?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?> />
            </div>
            <div class="col">
              <input type="url" class="form-control text" placeholder="主页（必填）" name="url" id="url" placeholder="<?php _e('http://'); ?>" value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireURL): ?> required<?php endif; ?> />
            </div>
        <?php endif; ?>
            </div>
            <div class="form-group" style="margin-top: 1rem;">
            <textarea class="form-control textarea" id="textarea" rows="3" name="text"></textarea>
            <p class="text-right" style="margin-top: 1rem;"><button type="submit" class="btn btn-primary btn-sm submit text-right"><?php _e('🚀评论🚀'); ?></button></p>
            </div>
            <?php $security = $this->widget('Widget_Security'); ?>
            <input type="hidden" name="_" value="<?php echo $security->getToken($this->request->getReferer())?>">
        </form>
        </div>
    <?php else: ?>
    <h3><?php _e('评论已关闭'); ?></h3>
    <?php endif; ?>
</div>